package cn.wolfcode.trip.base.domain;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import java.util.HashMap;
import java.util.Map;

@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
public class Region extends BaseDomain{

    public static final Integer STATE_NOMAL = 0; //普通
    public static final Integer STATE_COMMEND = 1; //推荐

    private String name;

    private Region parent;

    private Integer state = STATE_NOMAL;

    //把数据转成treeview格式,用于显示
    public Map<String,Object> toTreeView(){
        Map<String,Object> map = new HashMap<>();
        map.put("id",id);
        map.put("text",name);
        map.put("lazyLoad",true);
        //用于标签
        if(state == STATE_COMMEND){
            map.put("tags",new String[]{"推荐"});
        }
        //用于新增/更新回显
        if(parent != null){
            map.put("parentId",parent.getId());
            map.put("parentName",parent.getName());
        }
        return map;
    }

}